package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    /**
     * 根据id查询套餐
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        SetmealVO setmealVo =setmealService.getById(id);
        return Result.success(setmealVo);
    }


    /**
     * 修改套餐
     *
     * @return
     */
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐分页条件查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public Result selectPage(SetmealPageQueryDTO query){
        PageResult pageResult = setmealService.selectPage(query);
        return Result.success(pageResult);
    }

    /**
     *新增套餐
     */
    @PostMapping
    public Result insertSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.insertSetmeal(setmealDTO);
        return Result.success();
    }


    /**
     * 批量删除套餐
     */
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Integer> ids){
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 套餐起售、停售
     * 修改套餐状态
     */
    @PostMapping("/status/{status}")
    public Result updateStatusById(@PathVariable Integer status,Long id){
        setmealService.updateStatusById(id);
        return Result.success();
    }
}
